<!DOCTYPE html>
<html lang="en">
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>下单</title>
    <link rel="stylesheet" href="/js/bootstrap.min.css">
    <script src="/js/jquery-3.2.1.min.js"></script>
    <script src="/js/bootstrap.min.js"></script>
    <script type="text/javascript">
        $(function () {
            getParam();

            function getUrlParam(name) {
                var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
                var r = window.location.search.substr(1).match(reg);  //匹配目标参数
                if (r != null)
                    return unescape(r[2]);
                return null; //返回参数值
            };

            //获得url参数
            function getParam() {
                var userId = getUrlParam("userId");
                $("#adda").attr("href", "/kProduct/ShowUserProduct.html?userId=" + userId);
            };

            //点击事件提交订单
            $("#button").click(function () {
                var newOrder = $("#addForm form")[0];
                var formaDate = new FormData(newOrder);
                $.ajax({
                    url: "/applets/order/add",
                    type: "post",
                    data: formaDate,
                    cache: false,
                    contentType: false,
                    processData: false,
                    success: function (data) {
                        alert(data.msg);
                    }
                });
                return false;
            });
            var num = null;
            //根据购买数量,修改总价格
            $("#num").blur(function () {
                num = $("#num").val();
                var price = getUrlParam("price");
                $("#price").attr("value", num * price);
            });
            //加入收藏
            $("#button2").click(function () {
                num = $("#num").val();
                $.get("/Kshop/cart/collection", {
                    "userid": getUrlParam("userId"),
                    "prodid": getUrlParam("id"),
                    "num": num
                }, function (da) {
                    alert(da.msg);
                })
            });
        });
    </script>
</head>
<body>
<div class="container" id="addForm">
    <h2 class="text-center">商品修改</h2>

    <!--导航-->
    <ul class="nav nav-tabs">
        <li class="nav-item">
            <a class="nav-link active" href="#" id="adda">返回展示界面</a>
        </li>
    </ul>


    <form action="#" method="post">
        <div class="form-group">
            <h4 th:text="${'商品名:'+p.name}"></h4>
            <label>商品ID</label>
            <input type="number" name="prodid" class="form-control" th:value="${p.id}" readonly>
        </div>
        <div class="form-group">
            <label>用户ID</label>
            <input type="number" name="userid" class="form-control" th:value="${user}" readonly>
        </div>

        <div class="form-group">
            <label>地址</label>
            <div th:each="a:${ad}">
                <label class="radio-inline"><input type="radio" name="addr" th:value="${a.addr}"
                                                   th:text="${a.addr}"></label>
            </div>
        </div>
        <div class="form-group">
            <label>付款方式</label>
            <label class="radio-inline"><input type="radio" name="payType" value="微信">微信</label>
            <label class="radio-inline"><input type="radio" name="payType" value="支付宝">支付宝</label>
            <label class="radio-inline"><input type="radio" name="payType" value="银行卡">银行卡</label>
        </div>
        <div class="form-group">
            <label>购买量</label>
            <input type="number" name="num" class="form-control" id="num">
        </div>
        <div class="form-group" hidden>
            <label>订单状态</label>
            <input type="number" name="num" class="form-control" value="1">
        </div>
        <div class="form-group">
            <label>价格</label>
            <input type="number" name="price" id="price" class="form-control" readonly>
        </div>
        <div class="form-group" hidden>
            <label>是否评价</label>
            <label class="radio-inline"><input type="radio" name="iscomment" value="1" checked>是</label>
            <label class="radio-inline"><input type="radio" name="iscomment" value="0">否</label>
        </div>
        <div class="form-group">
            <input type="button" id="button" class="form-control" value="下单">
            <input type="button" id="button2" class="form-control" value="加入购物车">
        </div>
    </form>

</div>
</body>
</html>